﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class HostListItem : MonoBehaviour {

    [SerializeField] TextMeshProUGUI tmpRoomName;
    [SerializeField] TextMeshProUGUI tmpGameMode;
    [SerializeField] TextMeshProUGUI slotCount;
    [SerializeField] Button joinBtn;
    public System.Action<string, int> JoinBtnClbk { get; set; }

    float lifetime;
    string address;
    int port;
    float joinClickInterval;


    public float Lifetime { get => lifetime; }

    private void Update() {
        lifetime += Time.deltaTime;
        joinClickInterval += Time.deltaTime;
    }
    public void Refresh(string roomName_, GameType gameMode_, string slotCount_, string address_, int port_) {
        lifetime = 0;
        address = address_;
        port = port_;

        tmpRoomName.text = roomName_;
        tmpGameMode.text = gameMode_.ToString();
        slotCount.text = slotCount_;
    }
    public void OnJoinBtnClick() {
        if (null != JoinBtnClbk && joinClickInterval > 2) {
            JoinBtnClbk(address, port);
            joinClickInterval = 0;
        }
    }
}
